#include <stdio.h>
#include <SDL2/SDL.h>
#include <SDL2/SDL_opengl.h>

#include "nanovg.h"
#define NANOVG_GL2_IMPLEMENTATION
#include "nanovg_gl.h"

int width;
int height;

int main(void)
{
	int x = 0, y = 0;
    Uint8 quit = 1;
    SDL_Event event;
    SDL_Init(SDL_INIT_VIDEO);
    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION,3);
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION,3);
    SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 1);
    SDL_Window *window = SDL_CreateWindow(
                             "SDL2 - NANOVG",         //    const char* title
                             SDL_WINDOWPOS_UNDEFINED,  //    int x: initial x position
                             SDL_WINDOWPOS_UNDEFINED,  //    int y: initial y position
                             800,                      //    int w: width, in pixels
                             600,                      //    int h: height, in pixels
                             SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN          //    Uint32 flags: window options, see docs
                         );
    SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED );
	SDL_GetWindowSize(window, &width, &height);
    NVGcontext* vg = nvgCreateGL2(NVG_ANTIALIAS | NVG_STENCIL_STROKES);
	glViewport(0,0,width,height);
    while (quit)
    {
        while(SDL_PollEvent(&event))
        {
            if(event.type == SDL_QUIT)
            {
                quit = 0;
            }
			if(event.type == SDL_MOUSEMOTION)
			{
				x = event.button.x;
				y = event.button.y;
			}
        }
        SDL_SetRenderDrawColor(renderer, 0xd3, 0xd3, 0xd3, 0xff );
        SDL_RenderClear(renderer);
        nvgBeginFrame(vg, width,height, 1.0f);
        nvgBeginPath(vg);
        nvgCircle(vg, 250, 220, 50);
        nvgCircle(vg, 250, 120, 50);
        nvgRect(vg, 0,0, x, y);
        nvgPathWinding(vg, NVG_HOLE);
        nvgFillColor(vg, nvgRGBA(255, 192, 0, 255));
        nvgFill(vg);
        nvgEndFrame(vg);
        SDL_GL_SwapWindow(window);
    }
	nvgDeleteGL2(vg);
    SDL_DestroyWindow(window);
    SDL_Quit();
    return 0;
}


